#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;using ll=long long;using ui=unsigned int;using ull=unsigned ll;
bool Be;const int N=4e5+5,M=N*30;int T,rt;ll x;set<ll>cur;
struct node{int s;ll g,f;node operator +(const node &p)const{return {s+p.s,g+p.g,f+p.f+p.g*s};}};
struct tree{int tot,ls[M],rs[M];node f[M];
	void add(int &k,ll u,int v,ll l=1,ll r=1e12){if(u<l||r<u)return;if(!k)k=++tot;
		if(l==r)return f[k].s+=v,f[k].g+=u*v,f[k].f=f[k].g,void();
		ll mid=l+r>>1;add(ls[k],u,v,l,mid),add(rs[k],u,v,mid+1,r),f[k]=f[ls[k]]+f[rs[k]];
	}
	node askl(int k,int u,ll l=1,ll r=1e12){if(l==r)return (node){u,u*l,u*l};ll mid=l+r>>1;
		if(f[ls[k]].s>=u)return askl(ls[k],u,l,mid);return f[ls[k]]+askl(rs[k],u-f[ls[k]].s,mid+1,r);
	}
	node askr(int k,int u,ll l=1,ll r=1e12){if(l==r)return (node){u,u*l,u*l};ll mid=l+r>>1;
		if(f[rs[k]].s>=u)return askr(rs[k],u,mid+1,r);return askr(ls[k],u-f[rs[k]].s,l,mid)+f[rs[k]];
	}
}t;bool Ed;
int main(){
	freopen("kte.in","r",stdin),freopen("kte.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
//	cerr<<(&Be-&Ed)/1024.0/1024<<"\n";
	cin>>T;
	while(T--){cin>>x;
		if(cur.count(x))cur.erase(x),t.add(rt,x,-1);else cur.insert(x),t.add(rt,x,1);
		if(cur.empty()){cout<<"0\n";continue;}
		int n=cur.size(),l=1,r=n+1>>1,mid,ans;ll res=0;
		while(l<=r)if(mid=l+r>>1,t.askl(rt,mid).g>t.askr(rt,mid-1).g)l=mid+1,ans=mid;else r=mid-1;
		if(ans==(n+1>>1))res=t.f[rt].f*2-t.f[rt].g*(n+1);
		else{res=t.askr(rt,n-ans).g-t.askl(rt,ans).g;
			node p=t.askl(rt,ans-1),q=t.askr(rt,ans-1);res+=p.f+q.f-p.g*(p.s+1);
			if(ans>1)p=t.askl(rt,ans-2),q=t.askr(rt,ans-2),res+=p.f+q.f-p.g*(p.s+1);
		}cout<<res<<"\n";
	}
}

